﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using BomberManServer.Gaming.Object;
using BomberManServer.Utils;

namespace BomberManServer.Gaming.Socket
{
    // the connection associated to the player
    public class PlayerSocket
    {
        // the player
        public Player player { get; private set; }
        // the connection
        public TcpClient client { get; private set; }
        public bool connected { get; private set; }
        public bool active { get { return (activity>0); } }
        // if drops to 0 then client is disconnected
        private int activity;
        // time before disconnecting seconds*25
        private static int timeout = Constants.instance.secondsBeforeInactiv * Constants.instance.actions_per_second;

        public PlayerSocket(Player player)
        {
            this.player = player;
        }

        // Network Methods
        public void connect(TcpClient client) { activate(); connected = true; this.client = client; }
        public void disconnect() { connected = false; client = null; }

        // resets activity
        public void activate() {
            activity = timeout;
        }

        // called every turn, decrease activity
        public void ageing()
        {
            activity--;
        }
    }
}